var cr_id;
function getValueGridAssetChangeCategory(record) {
	cr_id = record.get('CR_ID');
	Ext.getCmp('comboAssetChangeCat').setValue(record.get('CHANGE_CATEGORY'));
	Ext.getCmp('reasonTextAssetChangeCat').setValue(record.get('CHANGE_REASON'));
	if (record.get('ACTIVE') == 'True') {
		Ext.getCmp('active_assetChangeCat').setValue(true);
	} else {
		Ext.getCmp('disactive_assetChangeCat').setValue(true);
	}
	Ext.getCmp('buttonAddAssetChangeCat').setText('Update');
}

function InputAssetChangeReason() {
	var comboAssetChangeCat = Ext.getCmp('comboAssetChangeCat').getValue();
	var reasonTextAssetChangeCat = Ext.getCmp('reasonTextAssetChangeCat')
			.getValue();
	var disactive_assetChangeCat = Ext.getCmp('disactive_assetChangeCat')
			.getValue();
	var no = Ext.getStore('Administration.AssetChangeReason').getCount();
	//var no=Ext.getStore('Administration.AssetChangeReason').getProxy().url = "./Services/DataMaster/AssetChangeReason/List";

	
	if (Ext.getCmp('active_assetChangeCat').getValue() == true)
		statusAssetChangeCat = true;
	else
		statusAssetChangeCat = false;

	if (comboAssetChangeCat == null || comboAssetChangeCat == '') {
		Ext.MessageBox.show({
			title : 'WARNING',
			msg : 'Field Change Category Required',
			icon : Ext.Msg.WARNING
		});
	} else if (reasonTextAssetChangeCat == null
			|| reasonTextAssetChangeCat == '') {
		Ext.MessageBox.show({
			title : 'WARNING',
			msg : 'Field Reason Required',
			icon : Ext.Msg.WARNING
		});
	} else if ((statusAssetChangeCat == null || statusAssetChangeCat == '')
			&& (disactive_assetChangeCat == null || disactive_assetChangeCat == '')) {
		Ext.MessageBox.show({
			title : 'WARNING',
			msg : 'Field Reason Required',
			icon : Ext.Msg.WARNING
		});
	} else {

		if (Ext.getCmp('buttonAddAssetChangeCat').getText() == 'Insert') {
			var dataAssetChangeCat = {
				CHANGE_CATEGORY : comboAssetChangeCat,
				CHANGE_REASON : reasonTextAssetChangeCat,
				ACTIVE : statusAssetChangeCat
			}

			var url = './Services/DataMaster/AssetChangeReason/Add';
			PostData(dataAssetChangeCat, url, "Insert");
		} else {
			var dataAssetChangeCat = {
				CR_ID : cr_id,
				CHANGE_CATEGORY : comboAssetChangeCat,
				CHANGE_REASON : reasonTextAssetChangeCat,
				ACTIVE : statusAssetChangeCat
			}
			var url = './Services/DataMaster/AssetChangeReason/Update';
			PostData(dataAssetChangeCat, url, "Update");
		}
		Ext.getStore('Administration.AssetChangeReason').load();
		Ext.getCmp('buttonAddAssetChangeCat').setText("Insert");
		emptyfieldAssetChange();
		RefreshAssetChangeCategory();
		
	}
}

function emptyfieldAssetChange() {
	//Ext.getCmp('comboAssetChangeCat').setValue('');
	Ext.getCmp('reasonTextAssetChangeCat').setValue('');
	Ext.getCmp('active_assetChangeCat').setValue(false);
	Ext.getCmp('disactive_assetChangeCat').setValue(false);
}

function DeleteAssetChangeCategory() {
	var record = Ext.getCmp('table_assetChangeReason').getSelectionModel().getSelection();

	if (record.length > 0) {
		Ext.MessageBox.confirm('Delete', 'Are you sure?', function(btn) {
			if (btn == 'yes') {
				for (var i = 0; i < record.length; i++) {
					var idasssetchangecat = record[i].get('CR_ID');
					var dataAssetChangeCat = {
						CR_ID : idasssetchangecat
					};
					var url = './Services/DataMaster/AssetChangeReason/Delete';
					PostData(dataAssetChangeCat, url, "Delete");
				}
				
				Ext.getCmp('buttonAddAssetChangeCat').setText('Insert');
				emptyfieldAssetChange();
				RefreshAssetChangeCategory();
			}
		});

	} else {
		Ext.MessageBox.show({
			title : 'WARNING!',
			msg : 'No Data Selected',
			icon : Ext.Msg.WARNING
		});

	}

}

function RefreshAssetChangeCategory() {
	var keyword = Ext.getCmp("comboAssetChangeCat").getValue();
	Ext.getStore('Administration.AssetChangeReason').removeAll();
	Ext.getStore('Administration.AssetChangeReason').getProxy().url = "./Services/DataMaster/AssetChangeReason/List?CHANGE_CATEGORY="+keyword+"";
	Ext.getStore('Administration.AssetChangeReason').load();
}